package com.cc.controller;

import com.cc.entity.Student;
import com.cc.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 33314
 * @version 1.0
 * @description: TODO
 * @date 2025/6/21 14:36
 */
@RestController
@RequestMapping("/stu")
public class StuController {
    @Autowired
    private StuService stuService;
    /** 
     * @description: 展示学生信息
     * @param: student 
     * @return: java.util.List<com.cc.entity.Student> 
     * @author 33314
     * @date: 2025/6/21 14:48
     */
    @PostMapping("/getListStu")
    public List<Student> getStuList(@RequestBody Student student) {
        return stuService.getStuList(student);
    }
    /**
     * @description: 添加学生信息
     * @param: student
     * @return: int
     * @author 33314
     * @date: 2025/6/21 14:50
     */
    @RequestMapping("/insertStu")
    public int insertStu(@RequestBody Student student){
        return stuService.insertStu(student);
    }
    /**
     * @description: 修改学生信息
     * @param: student
     * @return: int
     * @author 33314
     * @date: 2025/6/21 14:50
     */
    @RequestMapping("/updateStu")
    public int updateStu(@RequestBody Student student){
        return stuService.updateStu(student);
    }
    /**
     * @description: 通过学生id来删除学生信息
     * @param: studentId
     * @return: int
     * @author 33314
     * @date: 2025/6/21 14:54
     */
    @DeleteMapping("/deleteStu")
    public int deleteStu(@RequestBody Map<String, Integer> requestBody) {
        Integer studentId = requestBody.get("studentId");
        if (studentId != null) {
            return stuService.deleteStu(studentId);
        } else {
            System.out.println("未提供 studentId 参数，跳过删除操作");
            return 0; // 返回 0 表示未删除任何记录
        }
    }
    @RequestMapping("/getStuDetail")
    public Student getStuDetail(Integer studentId) {
        return stuService.getStuDetail(studentId);
    }
}
